package com.happycat.configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.catalina.security.SecurityConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import com.happycat.config.HappyCatConfigarution;
import com.happycat.mobile.model.AccountRole;
import com.happycat.mobile.model.UserMenu;
import com.happycat.mobile.service.UserMenuService;

@Component
public class RoleMenuRunner implements ApplicationRunner {
	
	@Autowired
	private HappyCatConfigarution happyCatConfigarution;
	@Autowired
	private UserMenuService userMenuService;
	@Override
	public void run(ApplicationArguments args) throws Exception {
		
		
		Map<String, List<AccountRole>> map = new ConcurrentHashMap<String, List<AccountRole>>();
		/**
		 * 设置资源（url）所需要的权限（角色）集合
		 */
		List<UserMenu> list = userMenuService.getMenuMappingRoleList();
		if(list != null && list.size() > 0) {
			for (UserMenu userMenu : list) {
				map.put(userMenu.getUrl(), userMenu.getAccountRoleList());
			}
		}
		happyCatConfigarution.setRoleMenu(map);
	}

}
